package org.andao.security.filter;

import javax.servlet.http.HttpServletRequest;

import org.andao.security.model.User;
import org.andao.security.service.impl.UserDetailsServiceImpl;
import org.springframework.security.Authentication;
import org.springframework.security.AuthenticationCredentialsNotFoundException;
import org.springframework.security.AuthenticationException;
import org.springframework.security.ui.switchuser.SwitchUserProcessingFilter;



/**
 * 
 * 用户切换过滤器扩展.<p>
 * 
 * @author Marco.hu(hzg139@163.com)
 */
public class ExSwitchUserProcessingFilter extends SwitchUserProcessingFilter{
		
	@Override
	protected Authentication attemptExitUser(HttpServletRequest request)throws AuthenticationCredentialsNotFoundException {		
	  Authentication original = super.attemptExitUser(request);       
        if(null != original){
        	User user = (User)original.getPrincipal();            
        	UserDetailsServiceImpl.loadUserAuthorities(user);
        }
		return original;
	}


	@Override
	protected Authentication attemptSwitchUser(HttpServletRequest request)	throws AuthenticationException {	
		Authentication targetUser = super.attemptSwitchUser(request); 		
		return targetUser;
	}

	
	
	
}
